﻿package mortal.game.utils
{
    import flash.events.*;
    import flash.net.*;

    public class DownLoadFileUtil extends Object
    {
        private static var file:FileReference;
        private static var onSaveComplete:Function;

        public function DownLoadFileUtil()
        {
            return;
        }// end function

        public static function downloadToDesktop(param1:String, param2:Function) : void
        {
            var _loc_3:URLRequest = null;
            _loc_3 = new URLRequest(param1);
            try
            {
                navigateToURL(_loc_3, "_blank");
                if (param2 != null)
                {
                    param2.call(null);
                }
            }
            catch (e:Error)
            {
            }
            return;
        }// end function

        private static function cancelEvents(event:Event) : void
        {
            if (file)
            {
                file.cancel();
                file.removeEventListener(Event.COMPLETE, cancelEvents);
                file.removeEventListener(IOErrorEvent.IO_ERROR, cancelEvents);
                file.removeEventListener(Event.CANCEL, cancelEvents);
                file.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, cancelEvents);
                file = null;
                if (onSaveComplete != null)
                {
                    if (!event || event.type != Event.CANCEL)
                    {
                        onSaveComplete();
                    }
                    onSaveComplete = null;
                }
            }
            return;
        }// end function

    }
}
